<?php
class Shell_Command_Run extends Shell_Command_Abstract_CommandBase implements Shell_Command_Abstract_IShellCommand
{
	public function __construct()
	{
		parent::__construct();
		$this->NAME = "run";	
	}
	
//*************************************************************************************************
	public function execute($arguments) 
	{
		echo "Running a custom script!\n";
		
		$script_dir = Core_Registry::read(Enum_RegistryItems::SCRIPT_DIR);
		$script_name = $arguments[0];
		
		// crop '\' or '/' on the ends of the string
		if ($script_dir[0] === '\\' || $script_dir[0] === '/') $script_dir[0]='';
		if ($script_dir[ strlen($script_dir-1) ] === '\\' || $script_dir[0] === '/') $script_dir[0]='';
		
		$script_dir = getcwd().'/'.$script_dir.'/';
		
		//echo "\nscript_dir=$script_dir\n";	
		
		/*try 
		{*/
			//@include $script_dir . $script_name . '.php';
			
			$script =  file_get_contents($script_dir . $script_name . '.php');
			$res = @eval($script);
			
		/*}
		catch(Exception $e)
		{
			echo "\nScript $script_name not found!\n";
		}*/
			
		if ($res === null)
		{
			echo "\nExecution finished successfully\n";
		}
		elseif($res === false)
		{
			echo "\nError(s) occurred while executing the script!\n";
		}
		else		
		{
			echo "\nScript returned: $res\n";
		}
		
		
		
	}

}